package ch.zbw.pra.sysventory.ui.gui.panels.scanpanel.subpanels;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JProgressBar;

import ch.zbw.pra.sysventory.ui.gui.utilities.TimerThread;

public class ProgressbarPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1757694309689566522L;
	private JProgressBar progressBar;
	// private JLabel scanRunLabel;
	private boolean threadShouldRunState;

	public ProgressbarPanel() {
		this.threadShouldRunState = false;
		this.setVisible(false);
		init();
	}

	public void init() {
		this.progressBar = new JProgressBar(0, 100);

		// this.scanRunLabel = new JLabel();
		this.progressBar.setValue(0);
		this.progressBar.setSize(1400, 500);
		this.progressBar.setString("                                                                          ");
		this.progressBar.setStringPainted(true);

		this.progressBar.setStringPainted(true);
		this.add(this.progressBar, BorderLayout.CENTER);
		// this.setSize(500, 400);
		// this.add(this.scanRunLabel);
	}

	public void setProgressBarValue(int statePercent) {
		int value = statePercent;
		if (value <= 100) {
			this.progressBar.setValue(value);
		}
	}

	public void startProgressBarSequenceOnProgressbarPanel() {
		// this.add(progressBar);
		this.threadShouldRunState = true;
		TimerThread tt = new TimerThread(this);
		tt.start();
	}

	public void stoppProgressBarThread() {
		setTextAbortedOnScanRunLabel();
		this.threadShouldRunState = false;
	}

	public boolean getThreadShouldRunState() {
		return this.threadShouldRunState;
	}

	public void setThreadShouldRun() {
		this.threadShouldRunState = true;
	}

	public void setTextRunningOnScanRunLabel() {
		this.progressBar.setString("                                                                          ");
		// this.progressBar.setString("Scanvorgang läuft, bitte warten");
		this.progressBar.setStringPainted(true);
	}

	public void setTextRunFinishedOnScanRunLabel() {
		this.progressBar.setString("Scanvorgang beendet");
		this.progressBar.setStringPainted(true);
	}

	public void setTextAbortedOnScanRunLabel() {
		this.progressBar.setString("Scanvorgang wurde gestoppt");
		this.progressBar.setStringPainted(true);
	}

}
